Ext.define('org.tity.extjs.TityGridModel', {
	extend : 'Ext.data.Model',
	xtype : 'tity-grid-model',
	syncImm : true,
	fields : [],
	grid : null,
	savingTaskId:-1,
	set : function(fieldName, newValue, options) {
		var me = this;
		if(me.store && me.store.grid && me.store.grid.editingRecord)
		{
			me.store.grid.oldSettingValue=null;
			me.store.grid.settingFieldName=null;
			try{
				me.store.grid.settingFieldName = fieldName;
				me.store.grid.oldSettingValue = me.store.grid.editingRecord.get(fieldName);
			} catch(e){}
			if(me.store.grid.oldSettingValue==null)
			{
				try{
					me.store.grid.oldSettingValue = me.get(fieldName);
				} catch(e){}
			}
			
		}
		
		var ret = this.callParent([fieldName, newValue, options]);
		if (me.syncImm && me.store.grid.syncImm) // 是否立即与服务器同步
		{
			clearTimeout(me.savingTaskId);
			me.savingTaskId=setTimeout(function() {
				me.store.sync({
					callback : function() {
						me.store.fireEvent("aftercellsync", fieldName, newValue, options);

						me.store.grid.editingRecord = null;
						me.store.grid.oldSettingValue = null;
						me.store.grid.settingFieldName = null;
						
					}
				});
			}, 160);
		}
		else
		{
			
			me.store.commitChanges();
			me.store.grid.editingRecord = null;
			me.store.grid.oldSettingValue = null;
			me.store.grid.settingFieldName = null;
		}
		me.store.fireEvent("valuesetted", fieldName, newValue, options);
		return ret;
	}
});

Ext.define('org.tity.extjs.TityGridStore', {
	extend : 'Ext.data.Store',
	remoteSort:true,
	xtype : 'tity-grid-store'
});

Ext.define('org.tity.extjs.TityGridPanel', {
	extend : 'Ext.grid.Panel',
	xtype : 'tity-grid',
	collapsible : false,
	//业务主题，用于在某些位置显示，提示用户
	topic:"",
	bufferedRenderer : false,
	//默认设置为false,为了避开DPI或网页放大而引起的栏次分割线错位
	columnLines : false,
	border : false,
	loadMask : false,
	forceFit : false,
	clicksToEdit : 2,
	gateway : null,
	api : null,
	editingRecord : null,
	sortableColumns : true,
	baseParams : null,
	editorWIndow:null,
	//编辑器 : 可以是表单ID(识别为自动关联)，表单配置(识别为弹出窗口)，或是返回表单ID，表单配置的函数
	editorForm:null, 
	// private
	pkFields : [],
	// private
	modelRef : null,
	pageSize : 100,
	//refreshAfterDelete : true, // 是否删除后刷新
	// private
	selModel : {
		pruneRemoved : false
	},
	multiSelect : false,
	viewConfig : {
		trackOver : false,
		enableTextSelection : true,
		loadMask : false
	},
	columns : [],
	menuEnable : true,
	initConfig : function(config) {

		var me = this;
		// 获得请求的网关地址
		this.gateway = config.gateway;
		if (!this.gateway) {
			this.gateway = $T.removeSplash(page.gateway)
		}

		if (config.columns == null || !Ext.isArray(config.columns))
			config.columns = [];
		//
		this.pkFields = [];
		var modelFields = [];
		var displayFields = [];
		displayFields.push({
			xtype : 'rownumberer',
			width : 40,
			sortable : false
		});
		
		
		function convertFactory(column)
		{
			return function(value,r){
				if(column.dataType=="date") {
					if(Ext.isNumeric(value))
					{
						value = new Date(value);
					}
				}
				if(column.convert) return column.convert(value,r);
				else return value;
			};
		}
		
		function setDefautRenderer(column)
		{
			var format=column.format;
			if(!column.renderer)
			{
				if(column.dataType=="date") {
					if(!format) format="Y-m-d H:i:s"
					 column.renderer = function(value){
						return Ext.Date.format(value, format);
					}
				}
			}
		}
		
		
		for (var i = 0; i < config.columns.length; i++) {
			var column = config.columns[i];
			if (column.ispk) {
				this.pkFields.push(column.dataIndex);
			}

			modelFields.push({
				name : column.dataIndex,
				type : column.dataType ? column.dataType : "string",
				convert : convertFactory(column)
				
			});

			if (column.xtype && column.xtype == "hidden") {
				continue;
			}

			if ($T.isEmpty(column.sortable))
				column.sortable = true;
			if ($T.isEmpty(column.groupable))
				column.groupable = false;
			if ($T.isEmpty(column.cellWrap))
				column.cellWrap = false;
//			if ($T.isEmpty(column.menuDisabled))
//				column.menuDisabled = true;
				
			setDefautRenderer(column);

			displayFields.push(config.columns[i]);

		}
		config.columns = displayFields;

		if ($T.isBlank(config.api))
			config.api = "";
		config.api = "/" + $T.removeSplash(config.api) + "/";
		this.api = config.api;
		if (config.baseParams == null)
			config.baseParams = {};
		this.baseParams = config.baseParams;

		// 处理Model部分
		this.modelRef = config.api + "-gird";
		if ($T.isEmpty(config.model))
			config.model = {
				idProperty : "id"
			};
		if ($T.isEmpty(config.model.idProperty))
			config.model.idProperty = "id";

		if (this.pkFields.length > 0) {
			config.model.idProperty = this.pkFields[0];
		}

		if ($T.isEmpty(config.syncImm))
			config.syncImm = true;
		// 定义Model的基础属性
		var modelcfg = {
			extend : 'org.tity.extjs.TityGridModel',
			syncImm : config.syncImm, // 是否立即对数据同步到服务端
			fields : modelFields
		};
		Ext.apply(modelcfg, config.model);
		if (!window.$T.smart.cmp_cache[this.modelRef]) {
			Ext.define(this.modelRef, modelcfg);
			window.$T.smart.cmp_cache[this.modelRef]=true;
		}

		if ($T.isEmpty(config.paging))
			config.paging = true;

		if (!config.pageSize)
			config.pageSize = 100; // 强制分页

		this.pageSize = config.pageSize;

		if ($T.isEmpty(config.store))
			config.store = {
				pageSize : 100
			};
		if ($T.isEmpty(config.store.pageSize))
			config.store.pageSize = 100;

		if (!$T.isEmpty(config.pageSize))
			config.store.pageSize = config.pageSize;

		var storecfg = this.getDefaultStoreConfig(config);
		Ext.apply(storecfg, config.store);

		var store = Ext.create('org.tity.extjs.TityGridStore', storecfg);
		
		store.on("beforeload",function( it, operation, eOpts){
			
			var ps=store.getProxy().extraParams;
			if(!ps) ps={};
			if(!me.baseParams) me.baseParams={};
			Ext.apply(ps, me.baseParams);
			store.getProxy().extraParams = ps;
			
			//人为选择
			if(me.isJustSelected==false)
			{
				 var queryBtn=Ext.getCmp(me.id+"-query-button");
				 var refreshBtn=Ext.getCmp(me.id+"-refresh-button");
				 window.$T.setAjaxUILock([queryBtn,refreshBtn],true);
			}
		});
		store.on("load",function( it, records, successful, operation, eOpts){
			
			var queryBtn=Ext.getCmp(me.id+"-query-button");
			var refreshBtn=Ext.getCmp(me.id+"-refresh-button");
			window.$T.setAjaxUILock([queryBtn,refreshBtn],false);
			
			if(!successful && operation.exception)
			{
				$T.showException(operation.error);
				//标记为成功，时后面的逻辑不再处理这个错误
				operation.success=true;
			}
			
			setTimeout(function(){ me.getSelectionModel().deselectAll(); },10);
			
			
		});

		config.store = store;

		if (!config.plugins)
			config.plugins = {};

		if (!config.plugins.cellediting) {
			config.plugins.cellediting = {
				clicksToEdit : 1
			};
		}

		config.plugins.cellediting.clicksToEdit = me.clicksToEdit;

		if (!config.plugins.cellediting.listeners)
			config.plugins.cellediting.listeners = {};
		if (!config.plugins.cellediting.listeners.beforeedit) {
			config.plugins.cellediting.listeners.beforeedit = function(editor, context, eOpts) {
				me.editingRecord = context.record;
				if ($T.isEmpty(context.cancelEdit))
					context.cancelEdit = false;
				me.fireEvent("beforecelledit", editor, context, eOpts);
				return !context.cancelEdit;
			}
		}

		// 延迟显示loadmask
		me.loadMaskTask = -1;
		config.loadMask = false; // 强制没有loadmask
		store.on("beforeload", function(st, operation, eOpts) {
			if (!me.isDisabled())
				try{me.unmask();}catch(e){}
			clearTimeout(me.loadMaskTask);
			me.loadMaskTask = setTimeout(function() {
				me.mask("读取中...")
			}, 1000)
		});
		store.on("load", function(st, records, successful, operation, eOpts) {
			if (!me.isDisabled())
				try{me.unmask();}catch(e){}
			clearTimeout(me.loadMaskTask);
		});

		// 分页
		if (config.paging) {
			config.bbar = {
				xtype : 'pagingtoolbar',
				displayInfo : true,
				displayMsg : '显示 {0} - {1} 行,共 {2} 行',
				emptyMsg : "无数据"
			};
		}

		// 处理查询条件等UI界面
		this.handlerSearchCondition(config);
		
		$T.panelService.processBorderConfig(this, config);
		$T.panelService.processQuickDefaultConfig(this, config);

		

		this.callParent([config]);

		var model = this.getStore().getModel();
		model.syncImm = config.syncImm;
		model.grid = this;
		store.grid = this;

		this.initMenuConfig(config);

		if (!$T.isEmpty(config.menu.disabled)) {
			this.menuEnable = !config.menu.disabled;
		}
		
		$T.panelService.processBorder(this,config);
		
	},
	conditionInputIds : [], // 条件查询输入框ID
	getConditionParams : function() {
		var ps = {};
		var ops = {};
		for (var i = 0; i < this.conditionInputIds.length; i++) {
			var input = Ext.getCmp(this.conditionInputIds[i]);
			ps[input.name] = input.getValue();
			ops[input.name] = input.op ? input.op : "=";
		}
		ps["___operators"] = Ext.util.JSON.encode(ops);
		return ps;

	},
	loadByCondition : function() {
		this.load(this.getConditionParams());
	},
	handlerSearchCondition : function(config) {
		var me = this;
		me.conditionInputIds = [];

		if (!config.condition)
			return;
		var items = config.condition.items;
		if (!items || items.length == 0)
			return;

		if (config.condition.type == "tbar") {
			this.handlerSearchTBar(config, items);
		}
		//
		else if (config.condition.type == "form") {
			this.handlerSearchForm(config, items);
		}

	},

	handlerSearchForm : function(config, items) {

		var me = this;

		if (!config.tbar)
			config.tbar = [];
		var tbar = config.tbar;
		var z = tbar.indexOf("->");
		tbar.push("-")
		tbar.push({
			xtype : "button",
			text : "重置",
			handler:function()
			{
				var fm=Ext.getCmp(me.id+"-condition-form");
				fm.getForm().reset();
				me.loadByCondition();
			}
		},{
			xtype : "button",
			text : "展开",
			handler:function()
			{
				var fm=Ext.getCmp(me.id+"-condition-form");
				fm.setVisible(!fm.isVisible());
			}
		});

		var columns = config.condition.columns;
		if (!columns)
			columns = 4;

		// 栏次容器
		var containers = [];
		var i=0;
		for (i = 0; i < columns; i++) {
			containers.push({
				items : [],
				xtype : 'container',
				style : 'marginRight:32px',
				columnWidth : 1 / columns,
				border : false
			});
		}

		var itm = null, ctn = null;
		for (i = 0; i < items.length; i++) {
			itm = items[i];
			ctn = containers[i % columns];

			itm.fieldLabel = itm.label;
			itm.anchor = "100%";
			itm.width = "100%";
			ctn.items.push(itm);
			this.processConditionItem(config, itm, i);
		}

		config.tbar = null;
		
		if(z==-1)
		{
			if(tbar[0] == "-")
			{
				tbar[0] = "->";
			}
			else
			{
				tbar.unshift("->");
			}
		}

		config.dockedItems = [{
			xtype : 'toolbar',
			dock : 'top',
			items : tbar
		}, {
			xtype : "form",
			id:me.id+"-condition-form",
			bodyPadding : 16,
			width : "100%",
			layout : 'column',
			items : containers
		}];

	},

	processConditionItem : function(config, itm, i) {
		var me = this;
		if (!itm.listeners)
			itm.listeners = {};
		if (!itm.id)
			itm.id = me.id + "-condition-input-" + i;

		this.conditionInputIds.push(itm.id);

		if (config.condition.delayLoad)
			return;

		if (itm.xtype == "textfield" || itm.xtype == "tity-textfield" || itm.xtype == "numberfield" || itm.xtype == "tity-numberfield") {
			itm.enableKeyEvents = true;

			itm.listeners.keypress = function(cmp, e, eOpts) {
				if (e.getKey() == e.ENTER) {
					me.loadByCondition();
				}
			}
		} else {

			itm.listeners.change = function(cmp, newValue, oldValue, eOpts) {
				me.loadByCondition();
			}
		}
	},

	handlerSearchTBar : function(config, items) {

		var me = this;
		
		//查找外部配置
//		function overrideItemConfig(defauts)
//		{
//			//var cfg=overrides[defauts.key];
////			for (i = 0; i < config.tbar.length ; i++) {
////				if(!Ext.isObject(config.tbar[i])) continue;
////				if(config.tbar[i].key==defauts.key)
////				{
////					cfg=config.tbar[i];
////					
//				//	Ext.apply(defauts,cfg);
////					
////				}
////			}
//			return defauts;
//		}

		if (!config.tbar)
			config.tbar = [];
		var tbarObj=null;
		var tbar  = null;
		if(Ext.isObject(config.tbar))
		{
			tbarObj=config.tbar;
			tbar=tbarObj.items;
		}
		else
		{
			tbar	= config.tbar;
		}
 
		var z = tbar.indexOf("->");
		var tbar2 = [];
		var i;
		var overrides={};
		//加入用户自定义的工具类项目
		if(z==-1)
		{
			for (i = 0; i < tbar.length ; i++) {
				if(!$T.isBlank(tbar[i].key))
				{
					overrides[tbar[i].key]=tbar[i];
					continue;
				}
				tbar2.push(tbar[i]);
			}
		}
		else
		{
			for (i = 0; i < z ; i++) {
				if(!$T.isBlank(tbar[i].key))
				{
					overrides[tbar[i].key]=tbar[i];
					continue;
				}
				tbar2.push(tbar[i]);
			}
		}
		 

		if (tbar2.length > 0)
			tbar2.push("-")

		//加入搜索项目
		var itm = null;
		for (i = 0; i < items.length; i++) {
			itm = items[i];
			if(itm.label && itm.label.length>0)
			{
				tbar2.push({
					xtype : "label",
					html : "<span style='margin-left:4px'>" + itm.label.removeEnds(":").removeEnds("：") + "</span><span style='font-weight:550;color:#999999;margin-left:3px'>:</span>"
				});
			}

			if (itm.xtype == "checkbox" || itm.xtype == "tity-checkbox") {
				if (!itm.style)
					itm.style = {};
				itm.style.paddingTop = "3px";
				itm.style.paddingBottom = "0px";

			}

			this.processConditionItem(config, itm, i);

			tbar2.push(itm);
		}

		if(z==-1) tbar2.push("->")  //后面的靠右
		
		var customRightItemCount=0;
		if( z>=0)
		{
			for (i = z; i < tbar.length; i++) {
				if(!$T.isBlank(tbar[i].key))
				{
					overrides[tbar[i].key]=tbar[i];
					continue;
				}
				tbar2.push(tbar[i]);
				if(Ext.isObject(tbar[i]))
				{
					customRightItemCount++;
				}
			}
		}
		
		
		var btns=[];
		btns.push({
			xtype : "button",
			key : "query",
			id:me.id+"-query-button",
			glyph:'xf002@FontAwesome',
			text : "查询",
			handler : function() {
				me.loadByCondition(this);
			}
		});
		
		btns.push({
			xtype:"button",
			text:"新建",
			key:"new",
			glyph:'xf067@FontAwesome',
			handler:function(){
					me.activeEditor("new");
			}
		});
		
		btns.push({
			xtype:"button",
			text:"刷新",
			key:"refresh",
			id:me.id+"-refresh-button",
			glyph:'xf021@FontAwesome',
			handler:function(){
					me.refresh();
			}
		});
		var hiddens=0;
		for (i = 0; i < btns.length; i++) {
			itm=btns[i];
			var key=itm.key;
			if(!$T.isBlank(key))
			{
				if(overrides[key]) //覆盖用户自定义部分
				{
					Ext.apply(itm,overrides[key]);
				}
			}
			
			//如果延迟载入，则一定要有查询按钮
			if(key=='query' && config.condition.delayLoad )
			{
				itm.hidden=false;
			}
			
			if(itm.hidden)
			{
				hiddens++;
			}
			
		}
 		//左右两侧都有按钮才需要出现分割线
		if(customRightItemCount>0 && hiddens<btns.length)
		{
			tbar2.push("-");
		}
		
		 
		for (var i = 0; i < btns.length; i++) {
			tbar2.push(btns[i]);
		}
		
		
		
		if(tbarObj)
		{
			tbarObj.items=tbar2;
		}
		else
		{
			config.tbar = tbar2;
		}
	},

	// private
	getDefaultStoreConfig : function(config) {
		var me = this;
		var crud = {
			create : "save-entity",
			read : config.paging ? "list-page" : "list",
			update : "save-entity",
			destory : "delete-entity"
		}

		var resultProperties = {

			totalProperty : "data.totalRows",
			rootProperty : "data.list",
			successProperty : "suc",
			messageProperty : "msg"

		}

		var api = this.gateway + this.api;
		var cfg = {
			model : this.modelRef,
			remoteSort : true,
			proxy : {
				api : {
					create : api + crud.create,
					read : api + crud.read,
					update : api + crud.update,
					destory : api + crud.destory
				},
				actionMethods : {
					read : 'POST',
					create : 'POST',
					update : 'POST',
					destroy : 'POST'
				},
				type : 'ajax',
				reader : {
					type : 'json',
					rootProperty : resultProperties.rootProperty,
					totalProperty : resultProperties.totalProperty,
					successProperty : resultProperties.successProperty,
					messageProperty : resultProperties.messageProperty
				},
				listeners : {
					exception : function(p, response, operation, eOpts) {
						if (me.editingRecord)
							me.editingRecord.set(me.settingFieldName, me.oldSettingValue);

						var json = response.responseJson;
						if (json.exception) {
							$T.showException(json.msg);
						} else {
							if (json.suc == false) {
								$T.toast(json.msg);
							}
						}

					}
				}
			},
			autoLoad : true
		}
		return cfg;
	},
	createMenu : function() {
		return $T.menuService.createMenu(this);
	},
	
 
	afterRender : function() {
		var me = this;
		this.callParent([]);
		this.getAndPrintColumnCode();
		this.getAndPrintSearchItemCode();
		// 阻止默认邮件菜单
		this.addListener("containercontextmenu", function(me, e, eOpts) {
			e.preventDefault();
		});

		// 显示右键菜单
		this.addListener("rowcontextmenu", function(ow, record, tr, rowIndex, e, eOpts) {
			e.preventDefault();

			if (!this.menuEnable)
				return;

			if (!me.menu) {
				me.menu = me.createMenu();
			}
			me.menu.from = "item";
			me.menu.rowIndex = rowIndex;
			me.menu.record = record;
			me.menu.showAt(e.getXY());
		});
		
		//行双击事件
		this.addListener("rowdblclick", function(ow, record, tr, rowIndex, e, eOpts) {
			me.activeEditor("detail",record);
		});
		
		//
		this.addListener("select", function(ow, record, tr, rowIndex, e, eOpts) {
			me.isJustSelected=true;
			setTimeout(function()  {
				me.isJustSelected=false;
			},250);
		});
 
	
		 
		
	},
	saveEntity : function(data, callback) {
		$T.listDataService.saveEntity(this, data, function(r) {
			callback && callback(r);
		});
	},
	latestLoadParameter : null,
	load : function(ps, options) {
		this.latestLoadParameter = ps;
		if (!ps)
			ps = {};
		Ext.apply(ps, this.baseParams);
		this.getStore().getProxy().extraParams = ps;
		this.getStore().load(options);
		
		
		//请加入按钮操作锁定
		
		
	},
	refresh : function() {
		this.load(this.latestLoadParameter);
	},
	/**
	 * 删除行,多主键时传入ID为Object
	 */
	deleteRow : function(id) {
		var me = this;
		if (!id) {
			$T.toast("未指定删除行的主键值");
			return;
		}

		var ps = {};

		if (Ext.isObject(id)) {
			ps = Ext.apply(ps, id);
		} else {
			if (this.pkFields.length == 0) {
				$T.toast("缺少主键配置");
				return;
			}
			ps[this.pkFields[0]] = id;
		}
		ps = Ext.apply(ps, this.baseParams);

		var url = me.gateway + me.api + "delete-entity";
		$T.ajax(url, ps, function(r) {
			if (!r.suc) {
				$T.toast(r.msg);
				return;
			}
			// if(me.refreshAfterDelete)
			// {
			 me.refresh();
			// }
			// else
			// {
			// 移除删除的行
//			var rowIndex = me.getStore().findBy(function(rcd, id) {
//				var matched = true;
//				for (var i = 0; i < me.pkFields.length; i++) {
//					var f = me.pkFields[i];
//					if (rcd.get(f) != ps[f]) {
//						matched = false;
//						break;
//					}
//				}
//				return matched;
//			});
//			if (rowIndex > -1) {
//				me.getStore().removeAt(rowIndex);
//			}

			// var node = me.getStore().getNodeById(nodeId);
			// if (node == null) {
			// $T.toast("被删节点已经不存在");
			// return;
			// }
			// // 移除节点操作
			// node.remove();
			// me.getStore().remove(node);
			// me.getStore().commitChanges();
			//
			// node = me.getStore().getNodeById(node.data.parent_id);
			// }

		});
	},
	
	clearSort:function()
	{
		this.getStore().sort('-any:', 'NONE');
	},
	
	// private
	/**
	 * @param type  操作类型  new(新增，空白表单，可指定data进行数据预填充),detail(查看详情，单主键时，data可以是主键值，或data可以是包含主键的jsonobject对象)
	 * */
	activeEditor:function(type,data)
	{
		if(!this.editorForm) return;
		
		var me=this;
		
		//如果是配置项目
		if(Ext.isObject(this.editorForm))
		{
			
			var title="";
			if(type=="new")
			{
				title="新建";
				title+=$T.isBlank(this.topic)?"":this.topic;
			}
			else
			{
				title="详情";
				title=($T.isBlank(this.topic)?"":this.topic)+title;
			}
				
			
		
			if(this.editorWIndow==null)
			{
				this.editorWIndow = Ext.create("org.tity.extjs.TityFromWindow", {
						title :title,
						width :  this.editorForm.width?this.editorForm.width:400,
						height : this.editorForm.height?this.editorForm.height:350,
						handler : function(cmp,callback) {
							
							Ext.getCmp(me.editorForm.id).save(false,function(r){
								callback(r);
								me.refresh();
							});
					},
					form :this.editorForm
				});
			}
			
			if(type=="new")
			{
				Ext.getCmp(this.editorForm.id).reset();
				if(Ext.isObject(data))
				{
					if(Ext.getClassName(data)=="") // 如果是Object
					{
						Ext.getCmp(this.editorForm.id).setData(data,true);
					}
					else
					{
						Ext.getCmp(this.editorForm.id).reset();
						Ext.getCmp(this.editorForm.id).loadRecord(data);
					}
				}
			}
			else if(type=="detail")
			{
				Ext.getCmp(this.editorForm.id).loadById(data);
			}
				
			this.editorWIndow.setTitle(title);
			this.editorWIndow.show();
			
		}
		
		if(Ext.isString(this.editorForm))
		{
			//
		}
		
		
		
		
	},
	// private
	initMenuConfig : function(config) {
		var me=this;
		var defaultItems = [{
			key : "new",
			text : '新建',
			index : 1 ,
			handler:function()
			{
				 me.activeEditor("new");
			}
		},{
			key : "detail",
			text : '详情',
			index : 2 ,
			handler:function()
			{
				 me.activeEditor("detail",me.menu.record.data);
			}
		}, {
			key : "delete",
			text : '删除',
			index : 3,
			handler : function() {
				Ext.Msg.confirm('删除数据行', '您确定要删除当前选中的行吗？', function(op) {
					if (op == 'yes') {
						me.deleteRow(me.menu.record.data);
					}
				});
			}
		}];

		$T.menuService.config(this, config, defaultItems);

	},
	// private
	getAndPrintColumnCode : function() {
		if (this.api == "//")
			return;
		var codes = [];
		codes.push(">>> 开始输出表格列配置  [" + this.id + "]");
		var url = this.gateway + this.api + "get-meta";
		$T.ajax(url, {}, function(r) {
			if (r == null)
				return;
			codes.push("[{");
			var cols = r.data.meta.columns;
			for (var i = 0; i < cols.length; i++) {
				var col = cols[i];
				if (col.ispk) {
					codes.push("\t\txtype : 'hidden',");
					codes.push("\t\tispk : " + col.ispk + ",");
				} else {
					if (col.type == "string") {
						codes.push("\t\tdataType : 'string',");
					} else if (col.type == "date") {
						codes.push("\t\tdataType : 'date',");
						codes.push("\t\talign : 'right',");
					} else if (col.type == "integer") {
						codes.push("\t\tdataType : 'int',");
					} else if (col.type == "biginteger") {
						codes.push("\t\tdataType : 'int',");
						codes.push("\t\talign : 'right',");
					} else if (col.type == "number") {
						codes.push("\t\tdataType : 'number',");
						codes.push("\t\talign : 'right',");
					} else if (col.type == "bool") {
						codes.push("\t\tdataType : 'boolean',");
					}
				}
				codes.push("\t\ttext : $T.i18n('" + col.label + "'),");
				codes.push("\t\tdataIndex : '" + col.field + "',");
				codes.push("\t\tcomments : '" + col.comments + "'");
				if (i < cols.length - 1) {
					codes.push("\t},{");
				}

			}
			codes.push("}]");
			codes.push(">>> 结束输出表格列配置 [" + this.id + "]");
			var code = "";
			for (var i = 0; i < codes.length; i++) {
				code += codes[i] + "\n";
			}

			console.log(code);

		});
	},
	// private
	getAndPrintSearchItemCode : function() {
		if (this.api == "//")
			return;
		var codes = [];
		codes.push(">>> 开始输出表格查询条件配置 [" + this.id + "]");
		var url = this.gateway + this.api + "get-meta";
		$T.ajax(url, {}, function(r) {
			if (r == null)
				return;
			codes.push("[{");
			var cols = r.data.meta.columns;
			for (var i = 0; i < cols.length; i++) {
				var col = cols[i];
				if (col.type == "string") {
					codes.push("\t\txtype : 'tity-textfield',");
				} else if (col.type == "date") {
					codes.push("\t\txtype : 'tity-datepicker',");
				} else if (col.type == "integer") {
					codes.push("\t\txtype : 'tity-numberfield',");
				} else if (col.type == "biginteger") {
					codes.push("\t\txtype : 'tity-numberfield',");
				} else if (col.type == "number") {
					codes.push("\t\txtype : 'tity-numberfield',");
				} else if (col.type == "bool") {
					codes.push("\t\txtype : 'tity-checkbox',");
				} else {
					codes.push("\t\txtype : 'tity-textfield',");
				}
				codes.push("\t\tlabel : $T.i18n('" + col.label + "'),");
				codes.push("\t\tname : '" + col.field + "',");
				codes.push("\t\top: '='");
				if (i < cols.length - 1) {
					codes.push("\t},{");
				}

			}
			
			codes.push("}]");
			codes.push(">>> 结束输出表格查询条件配置 [" + this.id + "]");
			var code = "";
			for (var i = 0; i < codes.length; i++) {
				code += codes[i] + "\n";
			}

			console.log(code);

		});
	}

});
